<!DOCTYPE html><html lang="cn" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>docker操作 | HustleLr</title><meta name="keywords" content="中间件"><meta name="author" content="HustleLr"><meta name="copyright" content="HustleLr"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Docker官网：https:&#x2F;&#x2F;www.docker.com&#x2F;官网文档：下拉最后Docs（Docker手册） 找手册选引擎查看安装文档 Docker安装1.卸载旧版本12345678yum remove docker \                  docker-client \                  docker-client-latest \">
<meta property="og:type" content="article">
<meta property="og:title" content="docker操作">
<meta property="og:url" content="http://greenfivebird.gitee.io/hustleblog/2022/03/06/docker%E6%93%8D%E4%BD%9C/index.html">
<meta property="og:site_name" content="HustleLr">
<meta property="og:description" content="Docker官网：https:&#x2F;&#x2F;www.docker.com&#x2F;官网文档：下拉最后Docs（Docker手册） 找手册选引擎查看安装文档 Docker安装1.卸载旧版本12345678yum remove docker \                  docker-client \                  docker-client-latest \">
<meta property="og:locale">
<meta property="og:image" content="http://greenfivebird.gitee.io/hustleblog/img/docker.webp">
<meta property="article:published_time" content="2022-03-06T15:05:21.000Z">
<meta property="article:modified_time" content="2022-03-06T15:08:29.317Z">
<meta property="article:author" content="HustleLr">
<meta property="article:tag" content="中间件">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://greenfivebird.gitee.io/hustleblog/img/docker.webp"><link rel="shortcut icon" href="/hustleblog/img/head.jpg"><link rel="canonical" href="http://greenfivebird.gitee.io/hustleblog/2022/03/06/docker%E6%93%8D%E4%BD%9C/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/hustleblog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/hustleblog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'docker操作',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-03-06 23:08:29'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.1"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">Loading...</div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/hustleblog/img/head.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/hustleblog/archives/"><div class="headline">Articles</div><div class="length-num">17</div></a></div><div class="data-item"><a href="/hustleblog/tags/"><div class="headline">Tags</div><div class="length-num">12</div></a></div><div class="data-item"><a href="/hustleblog/categories/"><div class="headline">Categories</div><div class="length-num">12</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/hustleblog/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/link/"><i class="fa-fw fas fa-link"></i><span> 外链</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/hustleblog/img/docker.webp')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/hustleblog/">HustleLr</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/hustleblog/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/link/"><i class="fa-fw fas fa-link"></i><span> 外链</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">docker操作</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2022-03-06T15:05:21.000Z" title="Created 2022-03-06 23:05:21">2022-03-06</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2022-03-06T15:08:29.317Z" title="Updated 2022-03-06 23:08:29">2022-03-06</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/hustleblog/categories/%E4%B8%AD%E9%97%B4%E4%BB%B6/">中间件</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="docker操作"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>Docker官网：<a target="_blank" rel="noopener" href="https://www.docker.com/">https://www.docker.com/</a><br>官网文档：下拉最后Docs（Docker手册） 找手册选引擎查看安装文档</p>
<h2 id="Docker安装"><a href="#Docker安装" class="headerlink" title="Docker安装"></a>Docker安装</h2><h4 id="1-卸载旧版本"><a href="#1-卸载旧版本" class="headerlink" title="1.卸载旧版本"></a>1.卸载旧版本</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">yum remove docker \</span><br><span class="line">                  docker-client \</span><br><span class="line">                  docker-client-latest \</span><br><span class="line">                  docker-common \</span><br><span class="line">                  docker-latest \</span><br><span class="line">                  docker-latest-logrotate \</span><br><span class="line">                  docker-logrotate \</span><br><span class="line">                  docker-engine</span><br></pre></td></tr></table></figure>
<h4 id="2-需要的安装包"><a href="#2-需要的安装包" class="headerlink" title="2.需要的安装包"></a>2.需要的安装包</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y yum-utils</span><br></pre></td></tr></table></figure>
<h4 id="3-设置镜像仓库（使用阿里云镜像地址）"><a href="#3-设置镜像仓库（使用阿里云镜像地址）" class="headerlink" title="3.设置镜像仓库（使用阿里云镜像地址）"></a>3.设置镜像仓库（使用阿里云镜像地址）</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="language-bash">更新yum软件包索引</span></span><br><span class="line">yum makecache fast</span><br></pre></td></tr></table></figure>
<h4 id="4-安装-Docker-引擎"><a href="#4-安装-Docker-引擎" class="headerlink" title="4.安装 Docker 引擎"></a>4.安装 Docker 引擎</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install docker-ce docker-ce-cli containerd.io</span><br></pre></td></tr></table></figure>
<h4 id="5-启动-Docker"><a href="#5-启动-Docker" class="headerlink" title="5.启动 Docker"></a>5.启动 Docker</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl start docker</span><br></pre></td></tr></table></figure>
<h4 id="6-使用-docker-version-查看是否安装成功"><a href="#6-使用-docker-version-查看是否安装成功" class="headerlink" title="6.使用 docker version 查看是否安装成功"></a>6.使用 docker version 查看是否安装成功</h4><h4 id="7-docker-run-hello-world"><a href="#7-docker-run-hello-world" class="headerlink" title="7.docker run hello-world"></a>7.docker run hello-world</h4><h4 id="8-查看一下下载的这个-hello-world-镜像"><a href="#8-查看一下下载的这个-hello-world-镜像" class="headerlink" title="8.查看一下下载的这个 hello-world 镜像"></a>8.查看一下下载的这个 hello-world 镜像</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker images</span><br></pre></td></tr></table></figure>
<p>了解：卸载docker</p>
<p>1.卸载依赖</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum remove docker-ce docker-ce-cli containerd.io</span><br></pre></td></tr></table></figure>
<p>2.删除资源</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rm -rf /var/lib/docker</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">/var/lib/docker	docker的默认工作路径</span></span><br></pre></td></tr></table></figure>
<p>底层原理<br>1.Docker是怎么工作的？<br>Docker是一个Client-Server结构的系统，Docker的守护进程运行在主机上，通过Sock而从客户端访问！<br>DockerServer接受到Docker-Client的指令，就会执行这个命令！</p>
<p>2.Docker为什么比VM快？<br>Docker有着比虚拟机更少的抽象层。<br>Docker利用的是宿主的内核，vm需要的是Guset OS。</p>
<p>所以说，新建一个容器的时候，docker不需要像虚拟机一样重新加载一个操作系统内核，避免引导，虚拟机是加载Guest OS，分钟级别的，<br>而docker是利用宿主机的操作系统，省略了这个复杂的过程，秒级！</p>
<hr>
<h2 id="Docker的常用命令"><a href="#Docker的常用命令" class="headerlink" title="Docker的常用命令"></a>Docker的常用命令</h2><hr>
<h4 id="帮助命令"><a href="#帮助命令" class="headerlink" title="帮助命令"></a>帮助命令</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker version	#显示docker版本信息</span><br><span class="line">docker info	#显示docker的系统信息，包括镜像和容器</span><br><span class="line">docker 命令 --help  #万能命令</span><br></pre></td></tr></table></figure>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">帮助文档地址：https://docs.docker.com/engine/reference/commandline</span><br></pre></td></tr></table></figure>
<h4 id="镜像命令（查看镜像）"><a href="#镜像命令（查看镜像）" class="headerlink" title="镜像命令（查看镜像）"></a>镜像命令（查看镜像）</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker images 查看所有本地的主机上的镜像</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@192 /]# docker images</span><br><span class="line">REPOSITORY    TAG       IMAGE ID       CREATED        SIZE</span><br><span class="line">hello-world   latest    d1165f221234   6 months ago   13.3kB</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="language-bash">解释</span></span><br><span class="line">REPOSITORY	镜像的仓库源</span><br><span class="line">TAG		镜像的标签</span><br><span class="line">IMAGE ID		镜像的id</span><br><span class="line">CREATED		镜像的创建时间</span><br><span class="line">SIZE		镜像的大小</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="language-bash">可选项</span></span><br><span class="line">  -a, --all             列出所有镜像</span><br><span class="line">  -q, --quiet        只显示镜像的id</span><br></pre></td></tr></table></figure>
<h4 id="搜索镜像"><a href="#搜索镜像" class="headerlink" title="搜索镜像"></a>搜索镜像</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker search  --filter=STARS=3000	#搜索出来的镜像就是STARS大于3000的</span><br></pre></td></tr></table></figure>
<h4 id="下载镜像"><a href="#下载镜像" class="headerlink" title="下载镜像"></a>下载镜像</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull  镜像名[:tag]	docker pull mysql</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">Using default tag: latest	#如果不写tag，默认就是latest	</span><br><span class="line">latest: Pulling from library/mysql</span><br><span class="line">a330b6cecb98: Pull complete 	#分层下载，docker image的核心 联合文件系统</span><br><span class="line">9c8f656c32b8: Pull complete </span><br><span class="line">88e473c3f553: Pull complete </span><br><span class="line">062463ea5d2f: Pull complete </span><br><span class="line">daf7e3bdf4b6: Pull complete </span><br><span class="line">1839c0b7aac9: Pull complete </span><br><span class="line">cf0a0cfee6d0: Pull complete </span><br><span class="line">1b42041bb11e: Pull complete </span><br><span class="line">10459d86c7e6: Pull complete </span><br><span class="line">b7199599d5f9: Pull complete </span><br><span class="line">1d6f51e17d45: Pull complete </span><br><span class="line">50e0789bacad: Pull complete </span><br><span class="line">Digest: sha256:99e0989e7e3797cfbdb8d51a19d32c8d286dd8862794d01a547651a896bcf00c	#签名</span><br><span class="line">Status: Downloaded newer image for mysql:latest</span><br><span class="line">docker.io/library/mysql:latest		#真实地址</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="language-bash">等价于它</span></span><br><span class="line">docker pull mysql</span><br><span class="line">docker pull docker.io/library/mysql:latest	</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="language-bash">指定版本下载</span></span><br><span class="line">docker pull mysql:5.7</span><br></pre></td></tr></table></figure>
<h4 id="删除镜像！"><a href="#删除镜像！" class="headerlink" title="删除镜像！"></a>删除镜像！</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker rmi 删除镜像！（docker images查看容器镜像）</span><br><span class="line">docker rmi -f 镜像id		#删除指定的镜像	</span><br><span class="line">docker rmi -f 镜像id	 镜像id 镜像id 镜像id 	#删除多个镜像</span><br><span class="line">docker rmi -f $(docker images -aq)	#删除全部镜像</span><br></pre></td></tr></table></figure>
<h2 id="容器命令"><a href="#容器命令" class="headerlink" title="容器命令"></a>容器命令</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">说明：我们有了镜像才可以创建容器，Linux，下载一个CentOS镜像来测试学习</span><br><span class="line">docker pull centos</span><br></pre></td></tr></table></figure>
<h4 id="新建容器并启动"><a href="#新建容器并启动" class="headerlink" title="新建容器并启动"></a>新建容器并启动</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run [可选参数] image</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="language-bash">参数说明</span></span><br><span class="line">--name=&quot;Name&quot;	容器名字 tomcat01	tomcat02，用来区分容器</span><br><span class="line">-d		后台方式运行</span><br><span class="line">-it		使用交互方式运行，进入容器查看内容</span><br><span class="line">-p		指定容器的端口  -p	8080:8080</span><br><span class="line">	-p ip:主机端口：容器端口</span><br><span class="line">	-p 主机端口：容器端口（常用）</span><br><span class="line">	-p 容器端口</span><br><span class="line">	容器端口</span><br><span class="line">-P		随机指定端口</span><br></pre></td></tr></table></figure>
<h4 id="启动并进入容器"><a href="#启动并进入容器" class="headerlink" title="启动并进入容器"></a>启动并进入容器</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="language-bash">测试，启动并进入容器</span></span><br><span class="line">[root@192 /]# docker run -it centos /bin/bash</span><br><span class="line">[root@9473a59dc902 /]# </span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="language-bash">从容器中退回主机</span></span><br><span class="line">exit	#直接容器停止并退出</span><br><span class="line">Ctrl + p + q 	#容器不停止退出</span><br></pre></td></tr></table></figure>
<h4 id="列出所有的运行的容器"><a href="#列出所有的运行的容器" class="headerlink" title="列出所有的运行的容器"></a>列出所有的运行的容器</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="language-bash">docker ps 命令	<span class="comment">#列出所有正在运行的容器</span></span></span><br><span class="line">-a		#列出当前正在运行的容器+带出历史运行过的容器</span><br><span class="line">-n=?		#显示最近创建的容器</span><br><span class="line">-q		#只显示容器的编号</span><br></pre></td></tr></table></figure>
<h4 id="删除容器"><a href="#删除容器" class="headerlink" title="删除容器"></a>删除容器</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker rm 容器id		#删除指定容器，不能删除正在运行的容器，如果要强制删除  rm -f</span><br><span class="line">docker rm -f $(docker ps -aq)	#删除所有容器</span><br><span class="line">docker ps -a -q|xargs docker rm	#删除所有的容器</span><br></pre></td></tr></table></figure>
<h4 id="启动和停止容器的操作"><a href="#启动和停止容器的操作" class="headerlink" title="启动和停止容器的操作"></a>启动和停止容器的操作</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker start 容器id		#启动容器</span><br><span class="line">docker restart 容器id		#重启容器</span><br><span class="line">docker stop 容器id		#停止当前正在运行的容器</span><br><span class="line">docker kill 容器id		#强制停止当前的容器</span><br></pre></td></tr></table></figure>
<hr>
<h2 id="Docker的常用命令-1"><a href="#Docker的常用命令-1" class="headerlink" title="Docker的常用命令"></a>Docker的常用命令</h2><hr>
<h4 id="后台启动容器"><a href="#后台启动容器" class="headerlink" title="后台启动容器"></a>后台启动容器</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">命令 docker run -d 镜像名！</span></span><br><span class="line">[root@192 /]# docker run -d center</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="language-bash">问题docker ps，发现CentOS停止了</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="language-bash">常见的坑，docker容器使用后台运行，就必须要有一个前台进程，docker发现没有应用，就会自动停止</span></span><br><span class="line"><span class="meta">#</span><span class="language-bash">nginx，容器启动后，发现自己没有提供服务，就会立刻停止，就是没有程序了</span></span><br></pre></td></tr></table></figure>
<h4 id="查看日志"><a href="#查看日志" class="headerlink" title="查看日志"></a>查看日志</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">docker logs -f -t --tail 容器，没有日志</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">显示日志</span></span><br><span class="line"> -tf			#显示日志</span><br><span class="line"> --tail number	#要显示日志条数</span><br><span class="line">[root@192 /]# docker logs -tf --tail 10 容器id</span><br></pre></td></tr></table></figure>
<h4 id="查看容器中的进程信息ps"><a href="#查看容器中的进程信息ps" class="headerlink" title="查看容器中的进程信息ps"></a>查看容器中的进程信息ps</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">命令 docker top 容器<span class="built_in">id</span></span></span><br></pre></td></tr></table></figure>
<h4 id="查看镜像的元数据"><a href="#查看镜像的元数据" class="headerlink" title="查看镜像的元数据"></a>查看镜像的元数据</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash"> 命令</span></span><br><span class="line">docker inspect 容器id</span><br></pre></td></tr></table></figure>
<h4 id="进入当前正在运行的容器"><a href="#进入当前正在运行的容器" class="headerlink" title="进入当前正在运行的容器"></a>进入当前正在运行的容器</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">我们通常容器都是使用后台方式运行的，需要进入容器，修改一些配置</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">命令</span></span><br><span class="line">docker exec -it 容器id /bin/bash  (名字也可以)</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">测试</span></span><br><span class="line">[root@localhost /]# docker ps</span><br><span class="line">CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES</span><br><span class="line">[root@localhost /]# docker images</span><br><span class="line">REPOSITORY   TAG       IMAGE ID       CREATED        SIZE</span><br><span class="line">centos       latest    300e315adb2f   9 months ago   209MB</span><br><span class="line">[root@localhost /]# docker run -it centos /bin/bash</span><br><span class="line">[root@72fea5655b71 /]# [root@localhost /]# docker ps</span><br><span class="line">CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES</span><br><span class="line">72fea5655b71   centos    &quot;/bin/bash&quot;   11 seconds ago   Up 10 seconds             quirky_lewin</span><br><span class="line">[root@localhost /]# docker exec -it 72fea5655b71 /bin/bash</span><br><span class="line">[root@72fea5655b71 /]# ls</span><br><span class="line">bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var</span><br><span class="line">[root@72fea5655b71 /]# ps -ef</span><br><span class="line">UID         PID   PPID  C STIME TTY          TIME CMD</span><br><span class="line">root          1      0  0 02:10 pts/0    00:00:00 /bin/bash</span><br><span class="line">root         15      0  0 02:11 pts/1    00:00:00 /bin/bash</span><br><span class="line">root         30     15  0 02:11 pts/1    00:00:00 ps -ef</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">方式二</span></span><br><span class="line">docker attach 容器id</span><br><span class="line">[root@localhost /]# docker attach 72fea5655b71</span><br><span class="line">正在执行当前的代码...</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">docker <span class="built_in">exec</span>		<span class="comment"># 进入容器后开启一个新的终端，可以在里面操作（常用）</span></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">docker attach		<span class="comment"># 进入容器正在执行的终端，不会启动新的进程！</span></span></span><br></pre></td></tr></table></figure>
<h4 id="从容器内拷贝文件到主机上"><a href="#从容器内拷贝文件到主机上" class="headerlink" title="从容器内拷贝文件到主机上"></a>从容器内拷贝文件到主机上</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">docker cp 容器id:容器内路径  目的的主机路径</span><br><span class="line"><span class="meta"># </span><span class="language-bash">查看当前主机目录下</span></span><br><span class="line">[root@localhost /]# cd /home</span><br><span class="line">[root@localhost home]# ls</span><br><span class="line">[root@localhost home]# touch gaop.java</span><br><span class="line">[root@localhost home]# ls</span><br><span class="line">gaop.java</span><br><span class="line">[root@localhost home]# docker ps</span><br><span class="line">CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES</span><br><span class="line">dced13c86a08   centos    &quot;/bin/bash&quot;   2 minutes ago   Up 2 minutes             vibrant_euclid</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">进入docker容器内部</span></span><br><span class="line">[root@localhost home]# docker attach dced13c86a08</span><br><span class="line">[root@dced13c86a08 /]# cd /home</span><br><span class="line">[root@dced13c86a08 home]# ls</span><br><span class="line"><span class="meta"># </span><span class="language-bash">在容器内新建一个文件</span></span><br><span class="line">[root@dced13c86a08 home]# touch test.java</span><br><span class="line">[root@dced13c86a08 home]# ls</span><br><span class="line">test.java</span><br><span class="line">[root@dced13c86a08 home]# exit</span><br><span class="line">exit</span><br><span class="line">[root@localhost home]# docker ps</span><br><span class="line">CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES</span><br><span class="line">[root@localhost home]# docker ps -a</span><br><span class="line">CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                       PORTS     NAMES</span><br><span class="line">dced13c86a08   centos    &quot;/bin/bash&quot;   3 minutes ago    Exited (0) 8 seconds ago               vibrant_euclid</span><br><span class="line">72fea5655b71   centos    &quot;/bin/bash&quot;   13 minutes ago   Exited (127) 4 minutes ago             quirky_lewin</span><br><span class="line">36f0981c797a   centos    &quot;/bin/bash&quot;   11 hours ago     Exited (0) 11 hours ago                cool_booth</span><br><span class="line">27086ed0f9f8   centos    &quot;/bin/bash&quot;   11 hours ago     Exited (127) 11 hours ago              flamboyant_archimedes</span><br><span class="line">1f228a5b1aae   centos    &quot;/bin/bash&quot;   11 hours ago     Exited (0) 11 hours ago                vigorous_lehmann</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">将文件拷贝出来到主机上</span></span><br><span class="line">[root@localhost home]# docker cp dced13c86a08:/home/test.java /home</span><br><span class="line">[root@localhost home]# ls</span><br><span class="line">gaop.java  test.java</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">拷贝是一个手动过程，未来我们使用 -v 卷的技术，可以实现</span></span><br></pre></td></tr></table></figure>
<hr>
<h2 id="Docker部署"><a href="#Docker部署" class="headerlink" title="Docker部署"></a>Docker部署</h2><h4 id="Docker安装Nginx"><a href="#Docker安装Nginx" class="headerlink" title="Docker安装Nginx"></a>Docker安装Nginx</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="language-bash">1. 搜索镜像 search 建议去hub.docker搜索，可以看到帮助文档</span> </span><br><span class="line"><span class="meta">#</span><span class="language-bash">2. 下载镜像 pull</span></span><br><span class="line"><span class="meta">#</span><span class="language-bash">3. 运行测试</span></span><br><span class="line">[root@localhost /]# docker images</span><br><span class="line">REPOSITORY   TAG       IMAGE ID       CREATED        SIZE</span><br><span class="line">nginx        latest    ad4c705f24d3   4 days ago     133MB</span><br><span class="line">centos       latest    300e315adb2f   9 months ago   209MB</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">-d 后台运行</span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">--name 给容器起名字</span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">-p 宿主机端口，容器内部端口</span></span><br><span class="line">[root@localhost /]# docker run -d --name nginx01 -p 3344:80 nginx</span><br><span class="line">10869087f8866bc79d506c2c63f5461c1e1f1f2ac96e6c27d21d7f55d78efbdb</span><br><span class="line">[root@localhost /]# docker ps</span><br><span class="line">CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES</span><br><span class="line">10869087f886   nginx     &quot;/docker-entrypoint.…&quot;   4 seconds ago   Up 3 seconds   0.0.0.0:3344-&gt;80/tcp, :::3344-&gt;80/tcp   nginx01</span><br><span class="line">[root@localhost /]# curl localhost:3344</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">进入容器</span></span><br><span class="line">[root@localhost /]# docker exec -it nginx01 /bin/bash</span><br><span class="line">root@10869087f886:/# whereis nginx</span><br><span class="line">nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx</span><br><span class="line">root@10869087f886:/# cd /etc/nginx </span><br><span class="line">root@10869087f886:/etc/nginx# ls</span><br><span class="line">conf.d	fastcgi_params	mime.types  modules  nginx.conf  scgi_params  uwsgi_params</span><br><span class="line">root@10869087f886:/etc/nginx# </span><br></pre></td></tr></table></figure>
<h4 id="Docker安装tomcat"><a href="#Docker安装tomcat" class="headerlink" title="Docker安装tomcat"></a>Docker安装tomcat</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">官方的使用</span></span><br><span class="line">docker run -it --rm tomcat:9.0</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">我们之前的启动都是后台，停止了容器之后，容器还是可以查到  docker run -it --<span class="built_in">rm</span> tomcat:9.0，一般用来测试用完即删</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">下载在启动</span></span><br><span class="line">docker pull tomcat</span><br><span class="line"><span class="meta"># </span><span class="language-bash">启动运行</span></span><br><span class="line">docker run -d -p 3355:8080 --name tomcat01 tomcat</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">测试访问没有问题</span></span><br><span class="line">[root@localhost ~]# docker run -d -p 3355:8080 --name tomcat01 tomcat</span><br><span class="line">94bdcfab8668bafef4af8c335fbc58e5ec785126d700432ab0b9150361f19825</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">进入容器</span></span><br><span class="line">[root@localhost ~]# docker exec -it 94bdcfab8668 /bin/bash</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">发现问题：1.linux命令少了	2.没有webapps。	阿里云镜像的原因，默认是最小的镜像，所有不必要的都剔除掉</span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">保证最小可运行的环境！</span></span><br><span class="line"></span><br><span class="line">root@94bdcfab8668:/usr/local/tomcat# cp -r  webapps.dist/* webapps</span><br></pre></td></tr></table></figure>
<h4 id="Docker安装-ES-kibana"><a href="#Docker安装-ES-kibana" class="headerlink" title="Docker安装 ES + kibana"></a>Docker安装 ES + kibana</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">es 暴露的端口很多</span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">es 十分耗内存</span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">es 的数据一般需要放置到安全目录！挂载</span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">--net somenetwork ? 网络配置</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">启动 elasticsearch</span></span><br><span class="line">docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e &quot;discovery.type=single-node&quot; elasticsearch:7.6.2</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="language-bash">启动了</span></span><br><span class="line"><span class="meta">#</span><span class="language-bash">查看cup状态</span></span><br><span class="line">docker stats</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="language-bash">测试一下es是否成功</span></span><br><span class="line">[root@localhost ~]# curl localhost:9200</span><br><span class="line">&#123;</span><br><span class="line">  &quot;name&quot; : &quot;9f6c1ab0cf0a&quot;,</span><br><span class="line">  &quot;cluster_name&quot; : &quot;docker-cluster&quot;,</span><br><span class="line">  &quot;cluster_uuid&quot; : &quot;CAxmCmAMTtqQX14R9To_zQ&quot;,</span><br><span class="line">  &quot;version&quot; : &#123;</span><br><span class="line">    &quot;number&quot; : &quot;7.6.2&quot;,</span><br><span class="line">    &quot;build_flavor&quot; : &quot;default&quot;,</span><br><span class="line">    &quot;build_type&quot; : &quot;docker&quot;,</span><br><span class="line">    &quot;build_hash&quot; : &quot;ef48eb35cf30adf4db14086e8aabd07ef6fb113f&quot;,</span><br><span class="line">    &quot;build_date&quot; : &quot;2020-03-26T06:34:37.794943Z&quot;,</span><br><span class="line">    &quot;build_snapshot&quot; : false,</span><br><span class="line">    &quot;lucene_version&quot; : &quot;8.4.0&quot;,</span><br><span class="line">    &quot;minimum_wire_compatibility_version&quot; : &quot;6.8.0&quot;,</span><br><span class="line">    &quot;minimum_index_compatibility_version&quot; : &quot;6.0.0-beta1&quot;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;tagline&quot; : &quot;You Know, for Search&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210924001935758.png" alt="image-20210924001935758"></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">赶紧关闭，增加内存的限制，修改配置文件 -e 环境配置修改</span></span><br><span class="line">docker run -d --name elasticsearch02 -p 9200:9200 -p 9300:9300 -e &quot;discovery.type=single-node&quot; -e ES_JAVA_OPTS=&quot;-Xms64m -Xmx512m&quot; elasticsearch:7.6.2</span><br><span class="line"><span class="meta"># </span><span class="language-bash">再次查看cup状态会发现降低</span></span><br></pre></td></tr></table></figure>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210924002057376.png" alt="image-20210924002057376"></p>
<hr>
<h4 id="可视化"><a href="#可视化" class="headerlink" title="可视化"></a>可视化</h4><ul>
<li>portainer（先用这个）</li>
<li>Rancher（CI/CD再用）</li>
</ul>
<h4 id="什么是portainer？"><a href="#什么是portainer？" class="headerlink" title="什么是portainer？"></a>什么是portainer？</h4><p>Docker图形化界面管理工具 ！提供一个后台面板供我们操作！</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker run -d -p 8088:9000 \</span><br><span class="line">--restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer</span><br></pre></td></tr></table></figure>
<p>访问测试：    外网：8088</p>
<p>可视化面板平时不会用</p>
<hr>
<h2 id="Docker镜像讲解"><a href="#Docker镜像讲解" class="headerlink" title="Docker镜像讲解"></a>Docker镜像讲解</h2><h3 id="镜像是什么"><a href="#镜像是什么" class="headerlink" title="镜像是什么"></a>镜像是什么</h3><p>镜像是一种轻量级、可执行的独立软件包，用来打包软件运行环境和基于运行环境开发的软件，它包含运行某个软件所需的所有内容，包括代码、运行时、库、环境变量和配置文件。</p>
<p>所有的应用，直接打包docker镜像，就可以直接跑起来！</p>
<h4 id="如何得到镜像："><a href="#如何得到镜像：" class="headerlink" title="如何得到镜像："></a>如何得到镜像：</h4><ul>
<li>从远程仓库下载</li>
<li>朋友拷贝给你</li>
<li>自己制作一个镜像DockerFile</li>
</ul>
<p>如何提交自己的镜像</p>
<h3 id="commit镜像"><a href="#commit镜像" class="headerlink" title="commit镜像"></a>commit镜像</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker commit 提交容器成为一个新的副本</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">命令和git原理类似</span></span><br><span class="line">docker commit -m=&quot;提交的描述信息&quot; -a=&quot;作者&quot; 容器id 目标镜像名：[TAG]</span><br></pre></td></tr></table></figure>
<p>实战测试</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">1.启动一个默认tomcat</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">2.发现这个默认的tomcat是没有webapps应用，镜像的原因，官方的镜像默认webapps下面是没有文件 的！</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">3.我自己拷贝进去了基本的文件</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">4.将我们操作过的容器通过commit提交为一个镜像！我们以后就使用修改过的镜像即可，这就是我们自己的一个修改过的镜像</span></span><br></pre></td></tr></table></figure>
<hr>
<h2 id="容器数据卷"><a href="#容器数据卷" class="headerlink" title="容器数据卷"></a>容器数据卷</h2><h3 id="什么是容器数据卷"><a href="#什么是容器数据卷" class="headerlink" title="什么是容器数据卷"></a>什么是容器数据卷</h3><hr>
<p>docker的理念回顾</p>
<p>将应用和环境打包成一个镜像！</p>
<p>数据？如果数据都在容器中，那么我们容器删除，数据就会丢失！需求：数据可以持久化</p>
<p>MySQL，容器删了，删库跑路！==需求：MySQL数据可以存储在本地！</p>
<p>容器之间可以有一个数据共享的技术！Docker容器中产生的数据，同步到本地！</p>
<p>这就是卷技术！目录的挂载，将我们容器内的目录，挂载到Linux上面！</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">总结一句话：容器的持久化和同步操作！容器间也是可以数据共享的</span></span><br></pre></td></tr></table></figure>
<h3 id="使用数据卷"><a href="#使用数据卷" class="headerlink" title="使用数据卷"></a>使用数据卷</h3><blockquote>
<p>方式一：直接使用命令来挂载  -v</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">docker run -it -v 主机目录：容器内目录</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="language-bash">测试</span></span><br><span class="line">[root@localhost home]# docker run -it -v /home/ceshi:/home centos /bin/bash</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">启动起来时候我们可以通过 docker inspect 容器<span class="built_in">id</span>	（不在在容器内使用此命令）</span></span><br></pre></td></tr></table></figure>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210927210145407.png" alt="image-20210927210145407"></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">测试文件的同步</span></span><br></pre></td></tr></table></figure>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210927210645168.png" alt="image-20210927210645168"></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">再来测试</span></span><br><span class="line">1.停止容器</span><br><span class="line">2.宿主机上修改文件</span><br><span class="line">3.启动容器</span><br><span class="line">4.容器内的数据依然是同步的</span><br></pre></td></tr></table></figure>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210927211659751.png" alt="image-20210927211659751"></p>
<p>好处：我们以后修改只需要在本地修改即可，容器会自动同步</p>
<h3 id="实战：安装MySQL"><a href="#实战：安装MySQL" class="headerlink" title="实战：安装MySQL"></a>实战：安装MySQL</h3><p>思考：MySQL的数据持久化问题！</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">获取镜像</span></span><br><span class="line">[root@localhost home]# docker pull mysql:5.7</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">运行容器，需要做数据挂载！  <span class="comment"># 安装启动MySQL，需要配置密码的，这是要注意点！</span></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">官方测试： docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="language-bash">启动我们的</span></span><br><span class="line">-d 后台运行</span><br><span class="line">-p 端口映射</span><br><span class="line">-v 卷挂载</span><br><span class="line">-e 环境配置</span><br><span class="line">--name 容器名字</span><br><span class="line">[root@localhost home]# docker run -d -p 3310:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root --name mysql01 mysql:5.7</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">启动成功之后，我们在本地使用连接工具来测试一下</span></span><br></pre></td></tr></table></figure>
<p>假设我们将容器删除，发现</p>
<p>我们挂载到本地的数据卷依旧没有丢失，这就实现了容器数据持久化功能！</p>
<h3 id="具名和匿名挂载"><a href="#具名和匿名挂载" class="headerlink" title="具名和匿名挂载"></a>具名和匿名挂载</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">匿名挂载</span></span><br><span class="line">-v 容器内路径！</span><br><span class="line">docker run -d -P --name nginx01 -v /etc/nginx ngix</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">查看所有的volume（卷）的情况</span></span><br><span class="line">[root@localhost home]# docker volume ls</span><br><span class="line">local     046f33cd58525a26c10ab95ce8316743c354452b98a369351407ffdb96d68047</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">这里发现，这种就是匿名挂载，我们在 -v 只写了容器内的路径，没有写容器外的路径！</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">具名挂载</span></span><br><span class="line">[root@localhost home]# docker run -d -P --name nginx02 -v juming-nginx:/etc/nginx ngix</span><br><span class="line">local     juming-nginx</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">通过 -v 卷名：容器内路径</span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">查看一下这个卷</span></span><br></pre></td></tr></table></figure>
<p><strong><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210927215829808.png" alt="image-20210927215829808"></strong></p>
<p>所有的docker容器内的卷，没有指定目录的情况下都是在 /var/lib/docker/volumes/**/_data</p>
<p>我们通过具名挂载可以方便的找到我们的一个卷，大多数情况在使用的具名挂载</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">如何确定是具名挂载还是匿名挂载，还是指定路径挂载！</span></span><br><span class="line">-v 容器内路径  		# 匿名挂载</span><br><span class="line">-v 卷名:容器内路径	   # 具名挂载</span><br><span class="line">-v /宿主机路径:容器内路径	# 指定路径挂载</span><br></pre></td></tr></table></figure>
<p>拓展：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">通过 -v 容器内路径：ro  rw 改变读写权限</span></span><br><span class="line">ro	readonly	# 只读</span><br><span class="line">rw	readwrite	# 可读可写</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">一旦这个设置了容器权限，容器对我们挂载出来的内容就有限定了！</span></span><br><span class="line">docker run -d -P --name nginx02 -v juming-nginx:/etc/nginx:ro ngix</span><br><span class="line">docker run -d -P --name nginx02 -v juming-nginx:/etc/nginx:rw ngix</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">ro 只要看到ro就说明这个路径只能通过宿主机来操作，容器内部是无法操作</span></span><br></pre></td></tr></table></figure>
<h3 id="初识Dockerfile"><a href="#初识Dockerfile" class="headerlink" title="初识Dockerfile"></a>初识Dockerfile</h3><p>Dockerfile就是用来构建docker镜像的构建文件！命令脚本！先体验一下！</p>
<p>通过这个脚本可以生成镜像，镜像一层一层的，脚本一个个的命令，每个命令都是一层！</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">串讲一个dockerfile文件，名字可以随机，建议dockerfile</span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">文件中的内容 指令（大写）参数</span></span><br><span class="line">FORM centos</span><br><span class="line"></span><br><span class="line">VOLUME [&quot;volume01&quot;,&quot;volume02&quot;]</span><br><span class="line"></span><br><span class="line">CMD echo &quot;---end---&quot;</span><br><span class="line">CMD /bin/bash</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">这里的每个命令，就是就是镜像的一层</span></span><br></pre></td></tr></table></figure>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210927224956015.png" alt=""></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">启动我们自己写的容器</span></span><br></pre></td></tr></table></figure>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210927225255999.png" alt="image-20210927225255999"></p>
<p>这个卷和外部一定有一个同步的目录</p>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210927225354400.png" alt="image-20210927225354400"></p>
<p>查看一下卷挂载路径</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cd v  按下TAB键</span><br></pre></td></tr></table></figure>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210927225932472.png" alt="image-20210927225932472"></p>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210927225846155.png" alt="image-20210927225846155"></p>
<p>测试一下刚才的文件是否同步</p>
<p>这种方式我们未来使用的十分多，因为我们通常会构建自己的镜像！</p>
<p>假设构建镜像时候没有挂载卷，要手动镜像挂载 -v 卷名:容器内路径！</p>
<h3 id="数据卷容器"><a href="#数据卷容器" class="headerlink" title="数据卷容器"></a>数据卷容器</h3><hr>
<p>多个mysql同步数据！</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">启动第一个容器</span></span><br><span class="line">[root@localhost /]# docker run -it --name docker01 gao/centos:1.0</span><br><span class="line"><span class="meta"># </span><span class="language-bash">启动第二个容器挂载第一个容器，实现容器的同步</span></span><br><span class="line">[root@localhost /]# docker run -it --name docker02 --volumes-from docker01 gao/centos:1.0</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">--volumes-from  只要通过它，就可以实现容器之间的共享</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">测试，可以删除docker01，查看一下docker02和docker03是否还可以访问这个文件</span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">测试依旧可以访问</span></span><br></pre></td></tr></table></figure>
<p>多个mysql实现数据共享</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost home]# docker run -d -p 3310:3306 -v /etc/mysql/conf.d -v /var/lib/mysql -e MYSQL_ROOT_PASSWORD=root --name mysql01 mysql:5.7</span><br><span class="line"></span><br><span class="line">[root@localhost home]# docker run -d -p 3310:3306 -v /etc/mysql/conf.d -v /var/lib/mysql -e MYSQL_ROOT_PASSWORD=root --name mysql02 --volumes-from mysql01 mysql:5.7</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">这个时候，可以实现两个容器数据同步！</span></span><br></pre></td></tr></table></figure>
<p>结论：</p>
<p>容器之间配置信息的传递，数据卷容器的生命周期一直持续到没有容器使用为止。</p>
<p>但是，一旦你持久化到了本地，这个时候，本地的数据是不会删除的！</p>
<hr>
<h2 id="DockerFile"><a href="#DockerFile" class="headerlink" title="DockerFile"></a>DockerFile</h2><p>dockerfile是用来构建 docker镜像的文件！命令参数脚本！</p>
<p>构建步骤：</p>
<p>1、编写一个 dockerfile 文件 </p>
<p>2、docker build 构建成为一个镜像</p>
<p>3、docker run 运行镜像</p>
<p>4、docker push 发布镜像（DockerHub、阿里云镜像仓库）</p>
<h3 id="DockerFile构建过程"><a href="#DockerFile构建过程" class="headerlink" title="DockerFile构建过程"></a>DockerFile构建过程</h3><p>基础知识：</p>
<p>1、每个保留关键字（指令 ）都是必须是大写字母</p>
<p>2、执行从上到下 顺序执行</p>
<p>3、# 表示注释</p>
<p>4、每一个指令都会 创建提交一个新的镜像层，并提交！</p>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210928112334090.png" alt="image-20210928112334090"></p>
<p>dockerfile是面向开发的，我们以后需要发布项目 ，做镜像，就需要编写 dockerfile文件，这个文件十分简单！</p>
<p>Docker镜像逐渐成为了企业交付的标准，必须要掌握！</p>
<p>步骤：开发、部署、运维。。。缺一不可！</p>
<p>DockerFile：构建文件，定义了一切的步骤，源代码</p>
<p>Dockerimages：通过DockerFile构建生成的镜像，最终发布和运行的产品！</p>
<p>Docker容器：容器就是镜像运行起来提供服务器</p>
<hr>
<h3 id="DockerFile的指令"><a href="#DockerFile的指令" class="headerlink" title="DockerFile的指令"></a>DockerFile的指令</h3><hr>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">FROM		# 基础镜像，一切从这里开始构建</span><br><span class="line">MAINTAINER	# 镜像是谁写的，镜像+邮箱</span><br><span class="line">RUN			# 镜像构建的时候需要运行的命令</span><br><span class="line">ADD			# 步骤：tomcat镜像，这个tomcat压缩包！添加内容</span><br><span class="line">WORKDIR		# 镜像的工作目录</span><br><span class="line">VOLUME		# 挂载的目录</span><br><span class="line">EXPOST		# 暴露端口</span><br><span class="line">CMD			# 指定这个容器启动的时候需要运行的命令，只有最后一个会生效，可被替代</span><br><span class="line">ENTRYPOINT	# 指定这个容器启动的时候需要运行的命令，可以追加命令</span><br><span class="line">ONBUILD		# 当构建一个被继承 DockerFile 这个时候就会运行 ONBUILD  的指令，触发指令</span><br><span class="line">COPY		# 类似ADD，将我们文件拷贝到镜像中</span><br><span class="line">ENV			# 构建的时候设置环境变量</span><br></pre></td></tr></table></figure>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210928112904949.png" alt="image-20210928112904949"></p>
<blockquote>
<p>创建一个自己的centos</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">1、编写Dockerfile的文件</span></span><br><span class="line">[root@localhost dockerfile]# vim mydockerfile-centos</span><br><span class="line">[root@localhost dockerfile]# cat mydockerfile-centos </span><br><span class="line">FROM centos</span><br><span class="line">MAINTAINER gao&lt;122121w@qq.com&gt;</span><br><span class="line"></span><br><span class="line">ENV MYPATH /usr/local</span><br><span class="line">WORKDIR $MYPATH</span><br><span class="line"></span><br><span class="line">RUN yum -y install vim</span><br><span class="line">RUN yum -y install net-tools</span><br><span class="line"></span><br><span class="line">EXPOSE 80</span><br><span class="line"></span><br><span class="line">CMD echo $MYPATH</span><br><span class="line">CMD echo &quot;---end---&quot;</span><br><span class="line">CMD /bin/bash</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">2、通过这个文件构建镜像</span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">命令 docker build -f dockerfile文件路径 -t 镜像名:[tag]</span></span><br><span class="line">[root@localhost dockerfile]# docker build -f mydockerfile-centos -t mycentos:0.1 .</span><br><span class="line">Successfully built 44ff8e7425e4</span><br><span class="line">Successfully tagged mycentos:0.1</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">3、测试运行</span></span><br></pre></td></tr></table></figure>
<p>对比之前centos我们增加之后的 镜像</p>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210928140831567.png" alt="image-20210928140831567"></p>
<p>我们可以列出本地的变更历史</p>
<p><img src="C:\Users\gaop\AppData\Roaming\Typora\typora-user-images\image-20210928140450712.png" alt="image-20210928140450712"></p>
<p>我们平时拿到一个镜像可以研究一下他是怎么做的了</p>
<blockquote>
<p>CMD和ENTRYPOINT 区别</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">CMD			# 指定这个容器启动的时候需要运行的命令，只有最后一个会生效，可被替代</span><br><span class="line">ENTRYPOINT	# 指定这个容器启动的时候需要运行的命令，可以追加命令</span><br></pre></td></tr></table></figure>
<p>测试cmd</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># </span><span class="language-bash">编写dockerfiile 文件</span></span><br><span class="line">[root@localhost dockerfile]# vim dockerfile-cmd-test</span><br><span class="line">FROM centos</span><br><span class="line">CMD [&quot;ls&quot;,&quot;-a&quot;]</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash"> 构建镜像</span></span><br><span class="line">[root@localhost dockerfile]# docker build -f dockerfile-cmd-test -t cmdtest .</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">run运行，发现我们 <span class="built_in">ls</span> -a 生效</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">想追加一个 -l  <span class="built_in">ls</span> -al</span></span><br><span class="line">[root@localhost dockerfile]# docker run 容器id -l</span><br><span class="line"><span class="meta"># </span><span class="language-bash">CMD的清理下 -l 替换了CMD的 [<span class="string">&quot;ls&quot;</span>,<span class="string">&quot;-a&quot;</span>] 命令，-l 不是命令所以报错！需要写完整的命令 <span class="built_in">ls</span> -al</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"># </span><span class="language-bash">编写追加命令</span></span><br><span class="line">[root@localhost dockerfile]# vim dockerfile-cmd-test</span><br><span class="line">FROM centos</span><br><span class="line">ENTRYPOINT [&quot;ls&quot;,&quot;-a&quot;]</span><br><span class="line"><span class="meta"># </span><span class="language-bash">docker run -l ,直接追加下去，相等于 <span class="built_in">ls</span> -al</span></span><br></pre></td></tr></table></figure>
<p>DockerFile中很多命令都十分相似，我们需要了解他们的区别。</p>
<script type="text&#x2F;javascript" src="https://unpkg.com/kity@2.0.4/dist/kity.min.js"></script><script type="text&#x2F;javascript" src="https://unpkg.com/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text&#x2F;javascript" src="https://unpkg.com/hexo-simple-mindmap@0.8.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text&#x2F;css" href="https://unpkg.com/hexo-simple-mindmap@0.8.0/dist/mindmap.min.css"></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="mailto:undefined">HustleLr</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="http://greenfivebird.gitee.io/hustleblog/2022/03/06/docker%E6%93%8D%E4%BD%9C/">http://greenfivebird.gitee.io/hustleblog/2022/03/06/docker%E6%93%8D%E4%BD%9C/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/hustleblog/tags/%E4%B8%AD%E9%97%B4%E4%BB%B6/">中间件</a></div><div class="post_share"><div class="social-share" data-image="/hustleblog/img/docker.webp" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/hustleblog/2022/03/06/JUC%E5%9F%BA%E7%A1%80/"><img class="prev-cover" src="/hustleblog/img/juc.jpeg@h_1280" onerror="onerror=null;src='/hustleblog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">JUC基础</div></div></a></div><div class="next-post pull-right"><a href="/hustleblog/2022/03/03/%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81/"><img class="next-cover" src="/hustleblog/img/suo.jfif" onerror="onerror=null;src='/hustleblog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">分布式锁</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>Related Articles</span></div><div class="relatedPosts-list"><div><a href="/hustleblog/2022/03/01/Kafka%E5%85%A5%E9%97%A8/" title="Kafka入门"><img class="cover" src="/hustleblog/img/kafka.jfif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-03-01</div><div class="title">Kafka入门</div></div></a></div><div><a href="/hustleblog/2022/03/01/es%E5%85%A5%E9%97%A8/" title="es入门"><img class="cover" src="/hustleblog/img/es.jfif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-03-01</div><div class="title">es入门</div></div></a></div><div><a href="/hustleblog/2021/06/23/kafka%E9%9D%A2%E8%AF%95%E9%A2%98/" title="kafka面试题"><img class="cover" src="/hustleblog/img/question.jfif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-06-23</div><div class="title">kafka面试题</div></div></a></div><div><a href="/hustleblog/2021/04/16/redis%E9%9D%A2%E8%AF%95%E9%A2%98/" title="redis面试题"><img class="cover" src="/hustleblog/img/question.jfif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-04-16</div><div class="title">redis面试题</div></div></a></div><div><a href="/hustleblog/2022/03/03/%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81/" title="分布式锁"><img class="cover" src="/hustleblog/img/suo.jfif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-03-03</div><div class="title">分布式锁</div></div></a></div><div><a href="/hustleblog/2022/03/01/redis%E9%9B%86%E7%BE%A4/" title="redis集群"><img class="cover" src="/hustleblog/img/redis.jfif" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-03-01</div><div class="title">redis集群</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/hustleblog/img/head.jpg" onerror="this.onerror=null;this.src='/hustleblog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">HustleLr</div><div class="author-info__description"></div></div><div class="card-info-data is-center"><div class="card-info-data-item"><a href="/hustleblog/archives/"><div class="headline">Articles</div><div class="length-num">17</div></a></div><div class="card-info-data-item"><a href="/hustleblog/tags/"><div class="headline">Tags</div><div class="length-num">12</div></a></div><div class="card-info-data-item"><a href="/hustleblog/categories/"><div class="headline">Categories</div><div class="length-num">12</div></a></div></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">Welcome to Wlr's Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Docker%E5%AE%89%E8%A3%85"><span class="toc-number">1.</span> <span class="toc-text">Docker安装</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E5%8D%B8%E8%BD%BD%E6%97%A7%E7%89%88%E6%9C%AC"><span class="toc-number">1.0.1.</span> <span class="toc-text">1.卸载旧版本</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E9%9C%80%E8%A6%81%E7%9A%84%E5%AE%89%E8%A3%85%E5%8C%85"><span class="toc-number">1.0.2.</span> <span class="toc-text">2.需要的安装包</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E8%AE%BE%E7%BD%AE%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93%EF%BC%88%E4%BD%BF%E7%94%A8%E9%98%BF%E9%87%8C%E4%BA%91%E9%95%9C%E5%83%8F%E5%9C%B0%E5%9D%80%EF%BC%89"><span class="toc-number">1.0.3.</span> <span class="toc-text">3.设置镜像仓库（使用阿里云镜像地址）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-%E5%AE%89%E8%A3%85-Docker-%E5%BC%95%E6%93%8E"><span class="toc-number">1.0.4.</span> <span class="toc-text">4.安装 Docker 引擎</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-%E5%90%AF%E5%8A%A8-Docker"><span class="toc-number">1.0.5.</span> <span class="toc-text">5.启动 Docker</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#6-%E4%BD%BF%E7%94%A8-docker-version-%E6%9F%A5%E7%9C%8B%E6%98%AF%E5%90%A6%E5%AE%89%E8%A3%85%E6%88%90%E5%8A%9F"><span class="toc-number">1.0.6.</span> <span class="toc-text">6.使用 docker version 查看是否安装成功</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#7-docker-run-hello-world"><span class="toc-number">1.0.7.</span> <span class="toc-text">7.docker run hello-world</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8-%E6%9F%A5%E7%9C%8B%E4%B8%80%E4%B8%8B%E4%B8%8B%E8%BD%BD%E7%9A%84%E8%BF%99%E4%B8%AA-hello-world-%E9%95%9C%E5%83%8F"><span class="toc-number">1.0.8.</span> <span class="toc-text">8.查看一下下载的这个 hello-world 镜像</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Docker%E7%9A%84%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4"><span class="toc-number">2.</span> <span class="toc-text">Docker的常用命令</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B8%AE%E5%8A%A9%E5%91%BD%E4%BB%A4"><span class="toc-number">2.0.1.</span> <span class="toc-text">帮助命令</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%95%9C%E5%83%8F%E5%91%BD%E4%BB%A4%EF%BC%88%E6%9F%A5%E7%9C%8B%E9%95%9C%E5%83%8F%EF%BC%89"><span class="toc-number">2.0.2.</span> <span class="toc-text">镜像命令（查看镜像）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%90%9C%E7%B4%A2%E9%95%9C%E5%83%8F"><span class="toc-number">2.0.3.</span> <span class="toc-text">搜索镜像</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%8B%E8%BD%BD%E9%95%9C%E5%83%8F"><span class="toc-number">2.0.4.</span> <span class="toc-text">下载镜像</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E9%95%9C%E5%83%8F%EF%BC%81"><span class="toc-number">2.0.5.</span> <span class="toc-text">删除镜像！</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%B9%E5%99%A8%E5%91%BD%E4%BB%A4"><span class="toc-number">3.</span> <span class="toc-text">容器命令</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%B0%E5%BB%BA%E5%AE%B9%E5%99%A8%E5%B9%B6%E5%90%AF%E5%8A%A8"><span class="toc-number">3.0.1.</span> <span class="toc-text">新建容器并启动</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8%E5%B9%B6%E8%BF%9B%E5%85%A5%E5%AE%B9%E5%99%A8"><span class="toc-number">3.0.2.</span> <span class="toc-text">启动并进入容器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%97%E5%87%BA%E6%89%80%E6%9C%89%E7%9A%84%E8%BF%90%E8%A1%8C%E7%9A%84%E5%AE%B9%E5%99%A8"><span class="toc-number">3.0.3.</span> <span class="toc-text">列出所有的运行的容器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E5%AE%B9%E5%99%A8"><span class="toc-number">3.0.4.</span> <span class="toc-text">删除容器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8%E5%92%8C%E5%81%9C%E6%AD%A2%E5%AE%B9%E5%99%A8%E7%9A%84%E6%93%8D%E4%BD%9C"><span class="toc-number">3.0.5.</span> <span class="toc-text">启动和停止容器的操作</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Docker%E7%9A%84%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4-1"><span class="toc-number">4.</span> <span class="toc-text">Docker的常用命令</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%90%8E%E5%8F%B0%E5%90%AF%E5%8A%A8%E5%AE%B9%E5%99%A8"><span class="toc-number">4.0.1.</span> <span class="toc-text">后台启动容器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E6%97%A5%E5%BF%97"><span class="toc-number">4.0.2.</span> <span class="toc-text">查看日志</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E5%AE%B9%E5%99%A8%E4%B8%AD%E7%9A%84%E8%BF%9B%E7%A8%8B%E4%BF%A1%E6%81%AFps"><span class="toc-number">4.0.3.</span> <span class="toc-text">查看容器中的进程信息ps</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E9%95%9C%E5%83%8F%E7%9A%84%E5%85%83%E6%95%B0%E6%8D%AE"><span class="toc-number">4.0.4.</span> <span class="toc-text">查看镜像的元数据</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%BF%9B%E5%85%A5%E5%BD%93%E5%89%8D%E6%AD%A3%E5%9C%A8%E8%BF%90%E8%A1%8C%E7%9A%84%E5%AE%B9%E5%99%A8"><span class="toc-number">4.0.5.</span> <span class="toc-text">进入当前正在运行的容器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BB%8E%E5%AE%B9%E5%99%A8%E5%86%85%E6%8B%B7%E8%B4%9D%E6%96%87%E4%BB%B6%E5%88%B0%E4%B8%BB%E6%9C%BA%E4%B8%8A"><span class="toc-number">4.0.6.</span> <span class="toc-text">从容器内拷贝文件到主机上</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Docker%E9%83%A8%E7%BD%B2"><span class="toc-number">5.</span> <span class="toc-text">Docker部署</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Docker%E5%AE%89%E8%A3%85Nginx"><span class="toc-number">5.0.1.</span> <span class="toc-text">Docker安装Nginx</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Docker%E5%AE%89%E8%A3%85tomcat"><span class="toc-number">5.0.2.</span> <span class="toc-text">Docker安装tomcat</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Docker%E5%AE%89%E8%A3%85-ES-kibana"><span class="toc-number">5.0.3.</span> <span class="toc-text">Docker安装 ES + kibana</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8F%AF%E8%A7%86%E5%8C%96"><span class="toc-number">5.0.4.</span> <span class="toc-text">可视化</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AFportainer%EF%BC%9F"><span class="toc-number">5.0.5.</span> <span class="toc-text">什么是portainer？</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Docker%E9%95%9C%E5%83%8F%E8%AE%B2%E8%A7%A3"><span class="toc-number">6.</span> <span class="toc-text">Docker镜像讲解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%95%9C%E5%83%8F%E6%98%AF%E4%BB%80%E4%B9%88"><span class="toc-number">6.1.</span> <span class="toc-text">镜像是什么</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E5%BE%97%E5%88%B0%E9%95%9C%E5%83%8F%EF%BC%9A"><span class="toc-number">6.1.1.</span> <span class="toc-text">如何得到镜像：</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#commit%E9%95%9C%E5%83%8F"><span class="toc-number">6.2.</span> <span class="toc-text">commit镜像</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%B9%E5%99%A8%E6%95%B0%E6%8D%AE%E5%8D%B7"><span class="toc-number">7.</span> <span class="toc-text">容器数据卷</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E5%AE%B9%E5%99%A8%E6%95%B0%E6%8D%AE%E5%8D%B7"><span class="toc-number">7.1.</span> <span class="toc-text">什么是容器数据卷</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E6%95%B0%E6%8D%AE%E5%8D%B7"><span class="toc-number">7.2.</span> <span class="toc-text">使用数据卷</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9E%E6%88%98%EF%BC%9A%E5%AE%89%E8%A3%85MySQL"><span class="toc-number">7.3.</span> <span class="toc-text">实战：安装MySQL</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B7%E5%90%8D%E5%92%8C%E5%8C%BF%E5%90%8D%E6%8C%82%E8%BD%BD"><span class="toc-number">7.4.</span> <span class="toc-text">具名和匿名挂载</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9D%E8%AF%86Dockerfile"><span class="toc-number">7.5.</span> <span class="toc-text">初识Dockerfile</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%8D%B7%E5%AE%B9%E5%99%A8"><span class="toc-number">7.6.</span> <span class="toc-text">数据卷容器</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#DockerFile"><span class="toc-number">8.</span> <span class="toc-text">DockerFile</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#DockerFile%E6%9E%84%E5%BB%BA%E8%BF%87%E7%A8%8B"><span class="toc-number">8.1.</span> <span class="toc-text">DockerFile构建过程</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#DockerFile%E7%9A%84%E6%8C%87%E4%BB%A4"><span class="toc-number">8.2.</span> <span class="toc-text">DockerFile的指令</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/hustleblog/2024/04/21/%E4%BB%A3%E7%A0%81%E9%9A%8F%E6%83%B3%E5%BD%95Day-2/" title="代码随想录Day 2"><img src="/hustleblog/img/code.png" onerror="this.onerror=null;this.src='/hustleblog/img/404.jpg'" alt="代码随想录Day 2"/></a><div class="content"><a class="title" href="/hustleblog/2024/04/21/%E4%BB%A3%E7%A0%81%E9%9A%8F%E6%83%B3%E5%BD%95Day-2/" title="代码随想录Day 2">代码随想录Day 2</a><time datetime="2024-04-20T16:31:56.000Z" title="Created 2024-04-21 00:31:56">2024-04-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hustleblog/2024/04/17/%E4%BB%A3%E7%A0%81%E9%9A%8F%E6%83%B3%E5%BD%95Day-1/" title="代码随想录Day 1"><img src="/hustleblog/img/code.png" onerror="this.onerror=null;this.src='/hustleblog/img/404.jpg'" alt="代码随想录Day 1"/></a><div class="content"><a class="title" href="/hustleblog/2024/04/17/%E4%BB%A3%E7%A0%81%E9%9A%8F%E6%83%B3%E5%BD%95Day-1/" title="代码随想录Day 1">代码随想录Day 1</a><time datetime="2024-04-17T14:26:46.000Z" title="Created 2024-04-17 22:26:46">2024-04-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hustleblog/2022/07/11/Gateway%E8%AE%B0%E5%BD%95/" title="Gateway记录"><img src="/hustleblog/img/gateway.webp" onerror="this.onerror=null;this.src='/hustleblog/img/404.jpg'" alt="Gateway记录"/></a><div class="content"><a class="title" href="/hustleblog/2022/07/11/Gateway%E8%AE%B0%E5%BD%95/" title="Gateway记录">Gateway记录</a><time datetime="2022-07-11T08:28:45.000Z" title="Created 2022-07-11 16:28:45">2022-07-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hustleblog/2022/04/01/%E6%9E%84%E5%BB%BA%E4%BA%8C%E5%8F%89%E6%A0%91/" title="构建二叉树"><img src="/hustleblog/img/%E4%BA%8C%E5%8F%89%E6%A0%91.webp" onerror="this.onerror=null;this.src='/hustleblog/img/404.jpg'" alt="构建二叉树"/></a><div class="content"><a class="title" href="/hustleblog/2022/04/01/%E6%9E%84%E5%BB%BA%E4%BA%8C%E5%8F%89%E6%A0%91/" title="构建二叉树">构建二叉树</a><time datetime="2022-03-31T16:29:49.000Z" title="Created 2022-04-01 00:29:49">2022-04-01</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hustleblog/2022/03/22/Java%E5%B8%B8%E8%A7%81%E5%87%A0%E7%A7%8D%E6%8E%92%E5%BA%8F/" title="Java常见几种排序"><img src="/hustleblog/img/sort.webp" onerror="this.onerror=null;this.src='/hustleblog/img/404.jpg'" alt="Java常见几种排序"/></a><div class="content"><a class="title" href="/hustleblog/2022/03/22/Java%E5%B8%B8%E8%A7%81%E5%87%A0%E7%A7%8D%E6%8E%92%E5%BA%8F/" title="Java常见几种排序">Java常见几种排序</a><time datetime="2022-03-22T09:51:45.000Z" title="Created 2022-03-22 17:51:45">2022-03-22</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/hustleblog/img/docker.webp')"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2024 By HustleLr</div><div class="footer_custom_text">Welcome to HustleLr's Blog</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Toggle Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/hustleblog/js/utils.js"></script><script src="/hustleblog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-show-text.min.js" data-mobile="false" data-text="有,志,者,事,竟,成" data-fontsize="15px" data-random="false" async="async"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>